package com.qys.livesMall.quartz.task.shop;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.qys.livesMall.shop.dao.H2ShopBaseDao;
import com.qys.livesMall.shop.modal.entity.H2ShopBase;
import com.qys.livesMall.shop.service.H2ShopStatisticsInfoService;
import com.qys.livesMall.shop.service.ShopStatisticsTeamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @menu OrderSettlementTask
 * @date 2023/07/12 11:46
 */
@Slf4j
@Component("ShopDataStatisticsTask")
public class ShopDataStatisticsTask {

    @Autowired
    private H2ShopStatisticsInfoService shopStatisticsInfoService;

    @Autowired
    private H2ShopBaseDao h2ShopBaseDao;

    public void exc(){
        log.info("店铺数据统计开始....");
        Integer pageNum=1;
        Integer pageSize=50;
        Integer dataSize=50;
        Integer total=0;
        Integer index=0;
        while (dataSize==50){
            List<H2ShopBase> shops=h2ShopBaseDao.getByPage(pageNum,pageSize);
            if (CollectionUtils.isNotEmpty(shops)){
                for(H2ShopBase shop:shops){
                    log.info("第"+index+"个店铺开始统计！");
                    shopStatisticsInfoService.initData(shop.getId());
                    log.info("第"+index+"个店铺开始统计结束！");
                    index++;
                }
            }else {
                shops=new ArrayList<>();
            }
            dataSize=shops.size();
            total=total+dataSize;
            pageNum++;
        }

        log.info("共"+total+"个店铺数据统计结束！");

    }
}

